package com.dispatcher;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;

import com.dispatcher.view.PullToRefreshWebView;

public class ProductActivity extends ActivityBase implements OnClickListener {
	private PullToRefreshWebView mPullRefreshWebView;
	ProgressBar pb;
	private RelativeLayout topLayout;
	private ImageButton backIBTN;
	private String initurl;
	private WebView mWebView;;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		
		setContentView(R.layout.product_layout);
		Intent intent = getIntent();
		String userID = intent.getStringExtra("userid");
		mPullRefreshWebView = (PullToRefreshWebView) findViewById(R.id.content_wv);
		pb=(ProgressBar)findViewById(R.id.pb);
		mPullRefreshWebView.setProgressBar(pb);
		mWebView = mPullRefreshWebView.getRefreshableView();

		mWebView.getSettings().setJavaScriptEnabled(true);
		 String sendno=intent.getStringExtra("sendno");
		 initurl = "http://m.kuaidi100.com/index_all.html?type=shunfeng&postid="+sendno;
		 
		 
		 mWebView.loadUrl(initurl);
		mWebView.setWebChromeClient(new WebChromeClient() {
			   public void onProgressChanged(WebView view, int progress) {
				   if(progress==100){
					   mWebView.postDelayed(new Runnable() {
						public void run() {
							
							pb.setVisibility(View.GONE);
							int h=mWebView.getContentHeight();
							mWebView.scrollTo(0, h-10);
						}
					}, 500);
				   }
			   }
			 });
		mWebView.setWebViewClient(new WebViewClient() {
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
	                view.loadUrl(url);
				return true;
			}
			public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
			     
			}
		});
	}

	
	
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
//		if (keyCode == KeyEvent.KEYCODE_BACK && contentWV.canGoBack()) {
//			contentWV.goBack();
//			return true;
//		}
		return super.onKeyDown(keyCode, event);
	}
	@Override
	protected void onSaveInstanceState(Bundle outState) {
	    //No call for super(). Bug on API Level > 11.
	}
	
	@Override
	protected void onResume() {
		super.onResume();
	}
	
	@Override
	protected void onPause() {
		super.onPause();
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case 0:
//			finish();
			break;
		default:
			break;
		}
	}
}
